//
//  SXNewsTableViewCell.m
//  NetEase-News
//
//  Created by 沈欣 on 2017/9/13.
//  Copyright © 2017年 沈欣. All rights reserved.
//

#import "SXNewsTableViewCell.h"
#import <YYWebImage.h>

@interface SXNewsTableViewCell ()

@property (weak, nonatomic) IBOutlet UIImageView *srcimgImageView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *sourceLabel;
@property (weak, nonatomic) IBOutlet UILabel *replayCountLabel;
@property (strong, nonatomic) IBOutletCollection(UIImageView) NSArray *srcimgImageViews;


@end

@implementation SXNewsTableViewCell

- (void)setNewsModel:(SXNewsModel *)NewsModel {
    _NewsModel = NewsModel;
    self.titleLabel.text = NewsModel.title;
    self.sourceLabel.text = NewsModel.source;
    self.replayCountLabel.text = NewsModel.replyCount.stringValue;
    
    [self.srcimgImageView yy_setImageWithURL:[NSURL URLWithString:NewsModel.imgsrc] placeholder:[UIImage imageNamed:@"placeholder"]];
    
    // 遍历出控件和对应的图片地址,完成图片的下载和展示
    if (NewsModel.imgextra.count > 0) {
        
        for (int i = 0; i < self.srcimgImageViews.count; i++) {
            // 取出控件
            UIImageView *srcImgView = self.srcimgImageViews[i];
            // 取出存放图片地址的字典
            NSDictionary *imgsrcDict = NewsModel.imgextra[i];
            // 取出字典里面的图片地址
            NSString *imgsrc = imgsrcDict[@"imgsrc"];
            
            // 下载和展示图片
            [srcImgView yy_setImageWithURL:[NSURL URLWithString:imgsrc] placeholder:[UIImage imageNamed:@"placeholder"]];
        }
    }
    [self.titleLabel setNeedsDisplay];
}

@end
